function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {
    $(".pass_info").submit(function (e) {
        e.preventDefault();

        // TODO 修改密码
        var old_password = $(':password[name="old_password"]').val();
        var new_password = $(':password[name="new_password"]').val();
        var new_password2 = $('input[name="new_password2"]').val();

        if (new_password != new_password2){
            alert("确认密码错误");
            return;
        }

        var params = {
            "old_password": old_password,
            "new_password": new_password
        };
        $.ajax({
            url: "/user/pass_info",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            headers: {"X-CSRFToken": getCookie("csrf_token")},
            success: function (resp) {
                if (resp.errno=="0"){
                    alert(resp.errmsg);
                    $(':password[name="old_password"]').val("");
                    $(':password[name="new_password"]').val("");
                    $(':password[name="new_password2"]').val("");
                }else {
                    alert(resp.errmsg)
                }
            }
        });


    })
});